package com.ruoyi.web.controller.mall.mallCompanyUser.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.web.controller.mall.mallCompanyUser.domain.MallCompanyUser;
import com.ruoyi.web.controller.mall.mallCompanyUser.service.IMallCompanyUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 企业用户Controller
 * 
 * @author ruoyi
 * @date 2021-01-18
 */
@Controller
@RequestMapping("/mall/mallCompanyUser")
public class MallCompanyUserController extends BaseController
{
    private String prefix = "mall/mallCompanyUser";

    @Autowired
    private IMallCompanyUserService mallCompanyUserService;

//    @RequiresPermissions("mall:mallCompanyUser:view")
    @GetMapping()
    public String mallCompanyUser()
    {
        return prefix + "/mallCompanyUser";
    }

    /**
     * 查询企业用户列表
     */
//    @RequiresPermissions("mall:mallCompanyUser:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(MallCompanyUser mallCompanyUser)
    {
        startPage();
        List<MallCompanyUser> list = mallCompanyUserService.selectMallCompanyUserList(mallCompanyUser);
        return getDataTable(list);
    }

    /**
     * 导出企业用户列表
     */
//    @RequiresPermissions("mall:mallCompanyUser:export")
    @Log(title = "企业用户", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(MallCompanyUser mallCompanyUser)
    {
        List<MallCompanyUser> list = mallCompanyUserService.selectMallCompanyUserList(mallCompanyUser);
        ExcelUtil<MallCompanyUser> util = new ExcelUtil<MallCompanyUser>(MallCompanyUser.class);
        return util.exportExcel(list, "mallCompanyUser");
    }

    /**
     * 新增企业用户
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存企业用户
     */
//    @RequiresPermissions("mall:mallCompanyUser:add")
    @Log(title = "企业用户", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(MallCompanyUser mallCompanyUser)
    {
        return toAjax(mallCompanyUserService.insertMallCompanyUser(mallCompanyUser));
    }

    /**
     * 修改企业用户
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        MallCompanyUser mallCompanyUser = mallCompanyUserService.selectMallCompanyUserById(id);
        mmap.put("mallCompanyUser", mallCompanyUser);
        return prefix + "/edit";
    }

    /**
     * 修改保存企业用户
     */
//    @RequiresPermissions("mall:mallCompanyUser:edit")
    @Log(title = "企业用户", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(MallCompanyUser mallCompanyUser)
    {
        return toAjax(mallCompanyUserService.updateMallCompanyUser(mallCompanyUser));
    }

    /**
     * 删除企业用户
     */
//    @RequiresPermissions("mall:mallCompanyUser:remove")
    @Log(title = "企业用户", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String[] ids)
    {
        return toAjax(mallCompanyUserService.deleteMallCompanyUserByIds(ids));
    }
}
